function PyResult() {
    this.form = this.InitForm();
    this.table = this.InitTableByBt();
}

PyResult.prototype.InitForm = function () {
    var form;
    $("#year").val($("#hidyear").val());
    layui.use('form', function () {
        form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功
        form.render();
    });
    return form;
}

var _table;
PyResult.prototype.InitTableByBt = function () {
    var table;
    var _this = this;
    var index = layer.load();
    layui.use('table', function () {
        var quarter = $('input[name="quarter"]:checked ').val();
        var month1 ="一月";
        var month2 ="二月";
        var month3 ="三月";
        if(quarter ==2){month1="四月";month2="五月";month3="六月"}
        if(quarter ==3){month1="七月";month2="八月";month3="九月"}
        if(quarter ==4){month1="十月";month2="十一月";month3="十二月"}

        table = layui.table;
        table.render({
            height: $(window).height() - 100
            , elem : '#list'
            , url: 'get_outwork_season_list' // 数据接口
            , page: false // 开启分页
            , id: 'uatmzpdsummary'
            , method: "post"
            ,cols: [
                [
                    {field:'rownum',title:'序号' ,width:40,align:'center',rowspan:'3'}
                    ,{field:'orgname',title:'部门', width:120,align: 'center',rowspan:'3'}
                    ,{field:'seasonSum',title:'当季合计发放金额' ,width:100,align: 'center',rowspan:'3'}
                    ,{align:'center',title:'季度内各月加班补贴实际发放情况',colspan:'6'}
                    ,{field:'remark',title:'备注' ,width:220,align: 'center',rowspan:'3'}
                ],
                [
                    {align:'center', colspan:'2',title : ''+month1+''},
                    {align:'center', colspan:'2',title : ''+month2+''},
                    {align:'center', colspan:'2',title : ''+month3+''}
                ],
                [ // 表头
                {field:'monthperson1', width:100,align:'center',title: '发放人数'}
                    ,{field:'monthmoney1', width:100,align:'center',title: '发放金额'}
                    ,{field:'monthperson2', width:100,align:'center',title: '发放人数'}
                    ,{field:'monthmoney2', width:100,align:'center',title: '发放金额'}
                    ,{field:'monthperson3', width:100,align:'center',title: '发放人数'}
                    ,{field:'monthmoney3', width:100,align:'center',title: '发放金额'}
                ]
            ]
            , request: {
                type: 'post'
            }
            , where: {
                year: $("#year").val(),
                quarter: $('input[name="quarter"]:checked ').val(),
                orgid: $("#szdw").val()
            }
            , done: function (res, page, count) {
                var year = $("#year").val();
                var quarter = $('input[name="quarter"]:checked ').val();

                // var orgname = $("#szdw").find("option:selected").text();
                // var orgname = $.trim(orgname);
                $("#title").html(year + "年第" + quarter + "季度加班补贴发放情况审核表");
                layer.close(index);
            }
        });
    })
    _table = table;
    return table;
}


PyResult.prototype.searchtable = function () {

    this.InitTableByBt();
    // _table.reload('uatmzpdsummary', {
    //
    //     where: {
    //         year: $("#year").val(),
    //         quarter: $('input[name="quarter"]:checked ').val(),
    //         orgid: $("#szdw").val()
    //     }
    // });
}


PyResult.prototype.excle = function () {
    top.ShowZheZhao();
    var tabledataJson = this.table.cache;
    var year = $("#year").val();
    var quarter = $('input[name="quarter"]:checked ').val();
    var orgname = $.trim($("#szdw").find("option:selected").text());
    tabledataJson['yearid'] = year;
    tabledataJson['quarter'] = quarter;
    tabledataJson['orgname'] = orgname;
    tabledataJson = JSON.stringify(tabledataJson);
    tabledataJson = tabledataJson.replace(/LAY_TABLE_INDEX/g, 'lay_TABLE_INDEX');
    $.ajax({
        type: "POST",
        url: "export_season_outwork",
        contentType: 'application/json',
        data: tabledataJson,
        beforeSend: function (XHR) {

        },
        success: function (data) {
            data = eval('(' + data + ')');
            if (data.result > 0) {
                //top.mylayui.msg('导出成功', {icon: 1});
                window.open(data.msg, '_self');
            }
            else {
                top.mylayui.msg(data.msg, {icon: 0});
            }
            top.ShowZheZhao();
        },
        complete: function (XHR) {
            top.mylayui.closeAll('loading');
        },
        error: function () {

        }
    });
}


var vOutWorkzpd = null;
$(function () {
    vOutWorkzpd = new PyResult();
})